package cn.wu.jishupeizhi.rabbitmq;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class BasicQueue {


    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Test
    public void pushRabbitMq1() throws Exception {
        String queueName = "simple.queue";
        String message = "Hello World!spring amqp!!";
        rabbitTemplate.convertAndSend(queueName, message);
        //sleep3秒
        Thread.sleep(3000);
    }

    @RabbitListener(queues = "simple.queue")
    public void pullRabbitMq1(String msg){
        System.out.println("pullRabbitMq1：消费者接收到simple.queue的消息：{"+msg+"}");
    }


}
